/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.dao.impl;

import com.ibatis.sqlmap.client.SqlMapClient;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.cx1.dao.api.IWeberDao;
import org.cx1.model.Weber;
import org.cx1.model.Weber;

/**
 *
 * @author ECH
 */
public class WeberDao implements IWeberDao {

    private SqlMapClient sqlMapClient;

    public WeberDao() {
        sqlMapClient = IbatisConnectionFactory.getSqlMapClient();
    }
 
    @Override
    public String add(Weber weber) {   
        String weberId = "";
        
        try {
            sqlMapClient.insert("weber.add", weber);
            weberId = weber.getEmail();
            
        } catch (SQLException ex) {
            Logger.getLogger(WeberDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return weberId;
    }

    @Override
    public List<Weber> getAll(int offset, int limit) {
        List<Weber> webers = new ArrayList<Weber>();
        
        try {
            Map map = new HashMap();
            map.put("limit", limit);
            webers = sqlMapClient.queryForList("weber.getAll", map);
        } catch (SQLException ex) {
            Logger.getLogger(WeberDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return webers;
    }

    @Override
    public int deleteById(String listName, String email) {
        int noOfRowsAffected = 0;
        
        try {
            Map map = new HashMap();
            map.put("listName", listName);
            map.put("email", email);
            noOfRowsAffected = sqlMapClient.delete("weber.deleteById", map);
        } catch (SQLException ex) {
            Logger.getLogger(WeberDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return noOfRowsAffected;
    }

    @Override
    public List<Weber> getAllByListName(String listName, int offset, int limit) {
        List<Weber> amenities = new ArrayList<Weber>();
        
        try {            
            Map map = new HashMap();
            map.put("listName", listName);
            map.put("limit", limit);
            amenities = sqlMapClient.queryForList("weber.getAllByListName", map);
        } catch (SQLException ex) {
            Logger.getLogger(WeberDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return amenities;
    }

    @Override
    public Weber getById(String id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int update(Weber weber) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
